Various embodiments of this disclosure relate to instruction relocation and, more particularly, to unaligned instruction relocation.
Programmers generally write source code in abstract programming languages. The resulting source code must be converted into an executable file containing assembly language embedded as binary code, which a machine can run. This conversion includes both compiling and linking.
Compiling is the act of generating an object file for each source code file. Often, an object file is incomplete in the sense that it refers to objects defined in other source code files. A linker combines parts of object files as needed to generate a complete and self-contained executable file. Among the tasks of the linker is relocation, which is the act of adjusting relocation targets. Relocation targets in an object file are memory locations that contain addresses of objects, such as functions, variables, or other data. Those addresses need to be adjusted after the memory locations of the objects in the final assembled code are known.
Hardware accelerators often offer only a small amount of memory for storing executable instructions. In some cases, parallel execution may be required, and the instructions stored must then include parallel instructions, which have the potential to require even more space than would be otherwise needed. Thus, in practice, the instructions on such hardware accelerators are compressed to take advantage of as many available bits as possible. As a result, some operator fields are not aligned to the byte. This can be problematic when an instruction refers to a relocatable address or an offset of an object, because current linking technology requires relocation targets to be aligned to the byte.
Some conventional systems use indirect addressing when performing relocation for hardware accelerators. If a certain memory instruction needs to access a field whose address is to be relocated, the memory instruction accesses a compile-time constant offset in a relocation table, also referred to as a table of contents. The table contains the relocated address, and the table is properly aligned to fit the applicable linker requirements.